package com.huawei.appmarket.service.thirdupdate;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.AsyncTask;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.StrikethroughSpan;
import android.text.style.TextAppearanceSpan;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.downloadengine.api.SplitTask;
import com.huawei.appgallery.foundation.application.pkgmanage.model.update.ApkUpgradeInfo;
import com.huawei.appmarket.service.deamon.download.remote.DownloadAgentService;
import com.huawei.hwid.core.constants.HwAccountConstants;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import com.huawei.secure.android.common.intent.SafeBundle;
import com.huawei.updatesdk.service.otaupdate.UpdateKey;
import java.util.List;
import o.azc;
import o.cjk;
import o.cjm;
import o.cks;
import o.cku;
import o.cku.c;
import o.dgm;
import o.Logger;
import o.doo;
import o.dqw;
import o.dss;
import o.dsu;
import o.dug;
import o.dvq;
import o.dvt;
import o.ekd;
import o.epv;
import o.epw;
import o.CollectCheck;
import o.eua;
import o.ActivityUtil;
import o.MinimumFactory;
import o.evk;
import o.ewb;
import o.ewm;
import o.ewm.e;
import o.ewm.h;
import o.ewm.j;
import o.ewm.n;

public class UpdateSdkFragment extends Fragment implements OnClickListener {
    private final BroadcastReceiver ʼ = new SafeBroadcastReceiver(this) {
        final /* synthetic */ UpdateSdkFragment ॱ;

        {
            this.ॱ = r1;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            String action = intent.getAction();
            SessionDownloadTask ˊ;
            if (dvq.ˊ().equals(action)) {
                ˊ = SessionDownloadTask.ˊ(intent.getBundleExtra("downloadtask.all"));
                if (ˊ != null && this.ॱ.ˏ.equals(ˊ.ˊˊ())) {
                    Bundle extras = intent.getExtras();
                    if (extras != null) {
                        this.ॱ.ˋ(extras.getInt("downloadtask.status", -1));
                    }
                }
            } else if (dvq.ˏ().equals(action)) {
                ˊ = SessionDownloadTask.ˊ(intent.getBundleExtra("downloadtask.all"));
                if (ˊ != null && this.ॱ.ˏ.equals(ˊ.ˊˊ())) {
                    int ʼॱ = ˊ.ʼॱ();
                    if (this.ॱ.ˊ != null) {
                        this.ॱ.ˊ.setProgress(ʼॱ);
                        this.ॱ.ॱॱ.setText(MinimumFactory.setMinimumFt((int) ((((float) this.ॱ.ˊ.getProgress()) / ((float) this.ॱ.ˊ.getMax())) * 100.0f)));
                    }
                }
            } else if ("com.huawei.appmarket.service.installerservice.Receiver".equals(action)) {
                action = intent.getStringExtra(DownloadAgentService.PACKAGE_NMAE_ARG);
                int intExtra = intent.getIntExtra(UpdateKey.STATUS, -99);
                int intExtra2 = intent.getIntExtra("resultcode", -99);
                if (this.ॱ.ˏ.equals(action) && this.ॱ.ˋ != null) {
                    if (2 == intExtra) {
                        this.ॱ.ˋ.ap_();
                    } else if (-1 == intExtra || -2 == intExtra) {
                        evk.ˏ(this.ॱ.ॱˋ(), n.ˊⁱ, 0).ˋ();
                        this.ॱ.ˋ.ॱ(this.ॱ.ˏ, intExtra2);
                    } else {
                        this.ॱ.ˋ.ˋ();
                    }
                }
            }
        }
    };
    private a ʽ;
    private ProgressBar ˊ;
    private ekd ˋ;
    private AlertDialog ˎ;
    private String ˏ;
    private AlertDialog ॱ;
    private TextView ॱॱ;
    private boolean ᐝ = false;
    private ApkUpgradeInfo ﹳ;
    private cku ﾞ;
    private boolean ﾟ = false;

    class a extends AsyncTask<Void, Void, ApkUpgradeInfo> {
        private String ˎ = null;
        final /* synthetic */ UpdateSdkFragment ˏ;

        protected /* synthetic */ Object doInBackground(Object[] objArr) {
            return ॱ((Void[]) objArr);
        }

        protected /* synthetic */ void onPostExecute(Object obj) {
            ˊ((ApkUpgradeInfo) obj);
        }

        public a(UpdateSdkFragment updateSdkFragment, String str) {
            this.ˏ = updateSdkFragment;
            this.ˎ = str;
        }

        protected void onPreExecute() {
            super.onPreExecute();
        }

        protected ApkUpgradeInfo ॱ(Void... voidArr) {
            Logger.ˎ("UpdateSdkFragment", "CheckThirdAppUpdateTask doInBackground");
            ApkUpgradeInfo ॱ = dug.ॱ(this.ˎ);
            if (ॱ != null) {
                return ॱ;
            }
            if (this.ˏ.ॱˋ() == null) {
                return null;
            }
            return dss.ॱ().ˎ(this.ˏ.ॱˋ(), this.ˎ, 0, 1);
        }

        protected void ˊ(ApkUpgradeInfo apkUpgradeInfo) {
            if (apkUpgradeInfo != null) {
                Logger.ˎ("UpdateSdkFragment", "check store client update success!" + apkUpgradeInfo.ʿ() + ",version:" + apkUpgradeInfo.ʽ());
                this.ˏ.ﹳ = apkUpgradeInfo;
                this.ˏ.ˋ(this.ˏ.ॱˋ(), apkUpgradeInfo);
                return;
            }
            if (this.ˏ.ˋ != null) {
                this.ˏ.ˋ.ˏ();
            }
            if (this.ˏ.ॱˋ() != null) {
                evk.ˏ(this.ˏ.ॱˋ(), n.ˌʽ, 0).ˋ();
            }
        }
    }

    public static UpdateSdkFragment ॱ(String str, boolean z) {
        UpdateSdkFragment updateSdkFragment = new UpdateSdkFragment();
        Bundle bundle = new Bundle();
        bundle.putString(HwAccountConstants.EXTRA_OPLOG_PKGNAME, str);
        bundle.putBoolean("ismustone", z);
        updateSdkFragment.ʼ(bundle);
        return updateSdkFragment;
    }

    private static void ॱ(ApkUpgradeInfo apkUpgradeInfo, TextView textView) {
        if (textView != null) {
            if (apkUpgradeInfo.ʼ() > 0) {
                Object ˊ = epw.ˊ(apkUpgradeInfo.ʻॱ());
                CharSequence spannableString = new SpannableString(ˊ);
                spannableString.setSpan(new StrikethroughSpan(), 0, ˊ.length(), 33);
                spannableString.setSpan(new TextAppearanceSpan("HwChinese-medium", 0, (int) textView.getTextSize(), null, null), 0, spannableString.length(), 33);
                textView.setText(spannableString);
                return;
            }
            textView.setVisibility(8);
        }
    }

    public void ˏ(Bundle bundle) {
        c_(true);
        super.ˏ(bundle);
        SafeBundle safeBundle = new SafeBundle(ˊॱ());
        this.ˏ = safeBundle.getString(HwAccountConstants.EXTRA_OPLOG_PKGNAME);
        this.ﾟ = safeBundle.getBoolean("ismustone");
        this.ʽ = new a(this, this.ˏ);
        this.ʽ.execute(new Void[0]);
    }

    private void ˋ(final Activity activity, final ApkUpgradeInfo apkUpgradeInfo) {
        if (activity != null) {
            CharSequence string;
            CharSequence ˊ;
            CharSequence string2;
            if (TextUtils.isEmpty(apkUpgradeInfo.ʼॱ())) {
                string = activity.getString(n.ߵ);
            } else {
                Object ʼॱ = apkUpgradeInfo.ʼॱ();
            }
            String str = "";
            str = "";
            str = "";
            str = epw.ˊ(apkUpgradeInfo.ʻॱ());
            if (apkUpgradeInfo.ʼ() > 0) {
                ˊ = epw.ˊ(apkUpgradeInfo.ʼ());
            } else {
                Object obj = str;
            }
            CharSequence ʽ = apkUpgradeInfo.ʽ();
            CharSequence ˊ2 = apkUpgradeInfo.ˊ();
            CharSequence string3 = activity.getString(n.ʻㆍ);
            CharSequence string4 = activity.getString(n.ʻᶥ);
            String string5 = activity.getString(n.ʻꜞ);
            View inflate = LayoutInflater.from(activity).inflate(h.ꞌॱ, null);
            ˏ((ImageView) inflate.findViewById(j.ᐧˎ));
            TextView textView = (TextView) inflate.findViewById(j.ˉˑ);
            TextView textView2 = (TextView) inflate.findViewById(j.ˊʽ);
            TextView textView3 = (TextView) inflate.findViewById(j.ᐝߵ);
            TextView textView4 = (TextView) inflate.findViewById(j.ʽॱ);
            ((TextView) inflate.findViewById(j.ˈˊ)).setText(string);
            textView.setText(ʽ);
            textView2.setText(ˊ);
            textView3.setText(ˊ2);
            ॱ(apkUpgradeInfo, textView4);
            ˋ(inflate);
            this.ﾞ = cku.ˏ(activity, cku.class, string3, null);
            this.ﾞ.ˊ(inflate);
            if (1 == apkUpgradeInfo.ˋᐝ()) {
                string2 = activity.getString(n.ʻꓸ);
                this.ᐝ = true;
                this.ﾞ.setCancelable(false);
                if (this.ﾟ) {
                    this.ﾞ.ˎ(-2, 8);
                }
            } else {
                ʽˊ();
                Object obj2 = string5;
            }
            this.ﾞ.ॱ(-1, string4);
            this.ﾞ.ॱ(-2, string2);
            ˋ((Context) activity);
            this.ﾞ.ॱ(new cks(this) {
                final /* synthetic */ UpdateSdkFragment ˎ;

                public void enableNetworking() {
                    if (doo.ˊ(this.ˎ.ॱˋ())) {
                        this.ˎ.ʽᐝ();
                        this.ˎ.ˋ(apkUpgradeInfo);
                        this.ˎ.ˊ(this.ˎ.ॱˋ());
                        if (this.ˎ.ˋ != null) {
                            this.ˎ.ˋ.ˊ();
                            return;
                        }
                        return;
                    }
                    evk.ˏ(activity, n.ʹˊ, 0).ˋ();
                    if (this.ˎ.ˋ != null) {
                        this.ˎ.ˋ.ˎ();
                    }
                }

                public void upgrade() {
                    this.ˎ.ॱ();
                    if (this.ˎ.ˋ != null) {
                        this.ˎ.ˋ.ˎ(this.ˎ.ᐝ);
                    }
                }

                public void ˋ() {
                }
            });
            this.ﾞ.ॱ(activity, "updateOTADialog");
        }
    }

    private void ॱ() {
        dsu o_dsu = new dsu();
        if (!this.ᐝ && o_dsu.ॱ(ॱˊ())) {
            boolean ˎ = dss.ॱ().ˎ();
            boolean ˏ = eua.ˏ().ˏ("never_reminder_auto_update", false);
            if (!ˎ && !ˏ) {
                cjk.ˎ().ˋ(ॱˋ(), new cjm("thirdappupdateremind.activity", null));
            }
        }
    }

    private void ˏ(ImageView imageView) {
        if (imageView != null) {
            if (azc.ˎ().ॱ() < 11 || azc.ˎ().ॱ() >= 17) {
                imageView.setVisibility(8);
            }
        }
    }

    private void ˋ(Context context) {
        int ॱ = azc.ˎ().ॱ();
        if (ॱ >= 11 && ॱ < 17) {
            c cVar = new c();
            cVar.ˋ(e.ﾟ);
            cVar.ˊ(context.getResources().getColor(ewm.c.ॱˎ));
            this.ﾞ.ॱ(-1, cVar);
        }
    }

    private void ˋ(View view) {
        try {
            ScrollView scrollView = (ScrollView) view.findViewById(j.ʻꜝ);
            if (VERSION.SDK_INT >= 22) {
                int ˎ = ewb.ˎ((Activity) view.getContext());
                scrollView.setPadding(ˎ, 0, ˎ, 0);
            }
        } catch (Exception e) {
            Logger.e("UpdateSdkFragment", e.toString());
        }
    }

    private void ʽˊ() {
        this.ﾞ.ˏ(new OnKeyListener(this) {
            final /* synthetic */ UpdateSdkFragment ˋ;

            {
                this.ˋ = r1;
            }

            public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
                if (i != 4 || keyEvent.getAction() != 0) {
                    return false;
                }
                if (this.ˋ.ˋ != null) {
                    this.ˋ.ˋ.ˎ(this.ˋ.ᐝ);
                }
                return true;
            }
        });
    }

    private void ˊ(Activity activity) {
        if (activity != null) {
            this.ˎ = new Builder(activity).create();
            View inflate = LayoutInflater.from(activity).inflate(h.ˉˋ, null);
            this.ˊ = (ProgressBar) inflate.findViewById(j.ʿꓸ);
            this.ॱॱ = (TextView) inflate.findViewById(j.ʿᶥ);
            inflate.findViewById(j.ꜝ).setOnClickListener(this);
            ((TextView) inflate.findViewById(j.ʿꜟ)).setText(n.ˏᵢ);
            int ˋ = epv.ˋ(activity, 16);
            this.ˎ.setView(inflate, ˋ, 0, ˋ, 0);
            this.ˎ.setCancelable(false);
            this.ˎ.setCanceledOnTouchOutside(false);
            this.ˎ.show();
            this.ॱॱ.setText(MinimumFactory.setMinimumFt(0));
        }
    }

    private void ˏ(final Activity activity) {
        if (activity != null) {
            Builder builder = new Builder(activity);
            builder.setMessage(n.ˊᵢ);
            builder.setPositiveButton(n.ˋՙ, new DialogInterface.OnClickListener(this) {
                final /* synthetic */ UpdateSdkFragment ˊ;

                public void onClick(DialogInterface dialogInterface, int i) {
                    this.ˊ.ˊ.setProgress(0);
                    this.ˊ.ˊ.setMax(0);
                    this.ˊ.ॱॱ.setText("");
                    this.ˊ.ॱ.dismiss();
                    this.ˊ.ˎ.dismiss();
                    this.ˊ.ˊ(this.ˊ.ˏ);
                    if (this.ˊ.ᐝ && this.ˊ.ﹳ != null) {
                        this.ˊ.ˋ(activity, this.ˊ.ﹳ);
                    } else if (this.ˊ.ˋ != null) {
                        this.ˊ.ˋ.ˎ(this.ˊ.ᐝ);
                    }
                }
            });
            builder.setNegativeButton(n.ˊˈ, new DialogInterface.OnClickListener(this) {
                final /* synthetic */ UpdateSdkFragment ॱ;

                {
                    this.ॱ = r1;
                }

                public void onClick(DialogInterface dialogInterface, int i) {
                    this.ॱ.ॱ.dismiss();
                }
            });
            this.ॱ = builder.create();
            this.ॱ.setCanceledOnTouchOutside(false);
            this.ॱ.show();
            ewb.ˊ(this.ॱ);
        }
    }

    private void ʽᐝ() {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(dvq.ˊ());
        intentFilter.addAction(dvq.ˏ());
        intentFilter.addAction("com.huawei.appmarket.service.installerservice.Receiver");
        ActivityUtil.registerReceiver(ॱˋ(), intentFilter, this.ʼ);
    }

    private void ˋ(int i) {
        switch (i) {
            case 4:
            case 7:
                if (!ActivityUtil.isAcitivtyNotValid(ॱˋ())) {
                    ˏ(this.ˎ);
                    return;
                }
                return;
            case 5:
            case 6:
            case 8:
                Logger.ˎ("UpdateSdkFragment", "download activity on download failed.");
                if (!ActivityUtil.isAcitivtyNotValid(ॱˋ())) {
                    ˏ(this.ˎ);
                    evk.ˏ(ॱˋ(), n.ˊॱ, 0).ˋ();
                    ॱˋ().finish();
                    return;
                }
                return;
            default:
                Logger.e("UpdateSdkFragment", "Unkonw message type: " + i + " ,package:");
                return;
        }
    }

    private void ˏ(AlertDialog alertDialog) {
        if (alertDialog != null) {
            try {
                alertDialog.dismiss();
            } catch (IllegalArgumentException e) {
                Logger.ˏ("UpdateSdkFragment", "dlProgressDialog dismiss IllegalArgumentException");
            }
        }
    }

    public void onClick(View view) {
        if (view.getId() == j.ꜝ) {
            ˏ(ॱˋ());
        }
    }

    public void ʼ() {
        if (this.ʽ != null) {
            this.ʽ.cancel(false);
        }
        super.ʼ();
    }

    public void ᐝ() {
        ActivityUtil.unregisterReceiver(ॱˋ(), this.ʼ);
        ˏ(this.ˎ);
        ˏ(this.ॱ);
        if (this.ﾞ != null) {
            cku.ˎ(ॱˋ(), "updateOTADialog");
            this.ﾞ = null;
        }
        super.ᐝ();
    }

    public void ॱ(Activity activity) {
        super.ॱ(activity);
        if (activity instanceof ekd) {
            this.ˋ = (ekd) activity;
        }
    }

    private void ˋ(final ApkUpgradeInfo apkUpgradeInfo) {
        SessionDownloadTask ˋ = dvt.ˏ().ˋ(apkUpgradeInfo.ᐝ());
        if (ˋ == null) {
            new dqw().ˏ(dqw.ˊ(apkUpgradeInfo.ᐝ(), apkUpgradeInfo.ॱʽ(), apkUpgradeInfo.ʿ() + ""), new dqw.c(this) {
                final /* synthetic */ UpdateSdkFragment ˎ;

                public void ˋ(SessionDownloadTask sessionDownloadTask) {
                    if (sessionDownloadTask != null) {
                        SplitTask splitTask;
                        if (apkUpgradeInfo.ॱʽ() == 0) {
                            splitTask = new SplitTask();
                            splitTask.ˋ(apkUpgradeInfo.ˈ());
                            splitTask.ˊ(apkUpgradeInfo.ʾ());
                            splitTask.ˊॱ(this.ˎ.ˏ);
                            splitTask.ˋ(apkUpgradeInfo.ʻॱ());
                            sessionDownloadTask.ˏ(splitTask);
                        }
                        sessionDownloadTask.ॱ(apkUpgradeInfo.ॱ());
                        sessionDownloadTask.ˏ(apkUpgradeInfo.ˊᐝ());
                        sessionDownloadTask.ॱॱ(apkUpgradeInfo.ˊ());
                        sessionDownloadTask.ˊ(apkUpgradeInfo.ˈ());
                        sessionDownloadTask.ʼ(apkUpgradeInfo.ᐝ());
                        sessionDownloadTask.ʽ(apkUpgradeInfo.ॱᐝ());
                        sessionDownloadTask.ʻ(apkUpgradeInfo.ʿ());
                        sessionDownloadTask.ˊ(dgm.ˎ(this.ˎ.ॱˋ()));
                        sessionDownloadTask.ॱ(apkUpgradeInfo.ˏˎ());
                        sessionDownloadTask.ॱˊ(apkUpgradeInfo.ॱʽ());
                        if (apkUpgradeInfo.ʼ() > 0) {
                            List ᐝˊ = sessionDownloadTask.ᐝˊ();
                            if (!CollectCheck.isEmpty(ᐝˊ)) {
                                splitTask = (SplitTask) ᐝˊ.get(0);
                                splitTask.ˏ(apkUpgradeInfo.ॱॱ());
                                splitTask.ॱ(apkUpgradeInfo.ʼ());
                                splitTask.ˎ(apkUpgradeInfo.ˈ());
                                splitTask.ˋ(apkUpgradeInfo.ʽॱ());
                                sessionDownloadTask.ˊ(apkUpgradeInfo.ʽॱ());
                            }
                        }
                        dvt.ˏ().ˏ(sessionDownloadTask);
                        return;
                    }
                    Logger.ˋ("UpdateSdkFragment", "doDownload sessionDownloadTask is null.");
                }

                public void ॱ() {
                    Logger.e("UpdateSdkFragment", "doDownload get bundle info fail.");
                }
            });
            return;
        }
        dvt.ˏ().ˎ(ˋ);
    }

    private void ˊ(String str) {
        SessionDownloadTask ˋ = dvt.ˏ().ˋ(str);
        if (ˋ != null) {
            dvt.ˏ().ॱ(ˋ.ʾ());
        }
    }
}
